import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import { buildColumns } from '@/utils'

export default function useTableColumn() {
  const filterSchemes = computed<CloudFilterBarScheme>(() => {
    return {
      widgets: [
        {
          widget: 'strong-search',
          placeholder: '默认按照区域名称搜索',
          options: [
            {
              label: '区域名称',
              field: 'name_keyword',
              maxLength: 30
            },
            {
              label: '域名',
              field: 'domain_keyword'
            }
          ]
        }
      ]
    }
  })
  const columns = computed(() =>
    buildColumns([
      {
        title: '区域名称',
        dataIndex: 'name'
      },
      {
        title: '区域CNAME',
        dataIndex: 'cname'
      },
      {
        title: '区域域名',
        dataIndex: 'resolve_domain_name'
      },
      {
        title: '关联节点',
        dataIndex: 'node_count',
        slotName: 'node_count'
      },
      {
        title: '关联站点',
        dataIndex: 'site_count',
        slotName: 'site_count'
      },
      {
        title: '添加时间',
        dataIndex: 'created_at',
        format: 'date-time',
        sortable: sortableSettings
      },
      {
        title: '操作',
        width: 116,
        slotName: 'action',
        cellClass: 'actions-cell'
      }
    ])
  )
  return {
    columns,
    filterSchemes
  }
}
